#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;

class Solution {
public:
    unordered_map<string, int> mp;
    string evaluate(string s, vector<vector<string>>& knowledge) {
        for (int i = 0; i < knowledge.size(); i++) {
            mp[knowledge[i][0]] = i;
        }
        string temp, ans;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] != '(') {
                ans += s[i];
            } else {
                int j = i + 1;
                while(s[j] != ')') {
                    temp += s[j];
                    j++;
                }
                if (!mp.count(temp)) {
                    ans += '?';
                } else {
                    ans += knowledge[mp[temp]][1];
                }
                i = j;
                temp = "";
            }
        }
        return ans;
    }
};

int main() {
    return 0;
}

/**
 * 2023.1.12
 * 模拟
*/